# 字典（ json 串 ）
# 字典是使用 键值对 存储数据，键值对之间使用 “,” 进行分隔

# 列表是 有序 的对象结合。
# 字典是 无序 的对象集合，键必须是唯一的。

xiaoming = {
    "name": "小明",
    "age": 18,
    "country": "china",
    "school": "xx小学"
}

print(xiaoming)


# 1. 取值
print(xiaoming["name"])
print(xiaoming["age"])
print(xiaoming["country"])
print(xiaoming["school"])


# 2. 增加/修改
xiaoming["height"] = 172.5
xiaoming["weight"] = 72.5
xiaoming["school"] = "xx中学"
print(xiaoming)


# 3. 删除
xiaoming.pop("height")
print(xiaoming)


# 4. 统计键值对数量
print(len(xiaoming))


# 5. 合并字典
# 注意：如果被合并的字典中包含已经存在的键值对，会覆盖原有的键值对
temp_dict = {
    "gender": "man",
    "car": "宝马"
}
xiaoming.update(temp_dict)
print(xiaoming)


# 6. 清空字典
# xiaoming.clear()
# print(xiaoming)


# 7. 循环遍历
for item in xiaoming:
    print("%s - %s" % (item, xiaoming[item]))

